<form id="form-org" class="form-horizontal">
	<input name="orgId" type="hidden">
	<div class="form-group">
		<label class="control-label col-xs-4">机构代码:</label>
		<div class="col-xs-8"><input name="orgCode" type="text" class="form-control">
		</div>
	</div>
	<div class="form-group">
		<label class="control-label col-xs-4"><span class="must-msg">*&nbsp;</span>名称:</label>
		<div class="col-xs-8"><input name="name" type="text"
			class="form-control" data-validation-engine="validate[required,maxSize[50]]"	placeholder="请输入组织名称"
			data-errormessage-value-missing="请输入组织名称" data-errormessage-range-overflow="名称过长(最长50位)"></div>
	</div>
	<div class="form-group">
		<label class="control-label col-xs-4"><span class="must-msg">*&nbsp;</span>简称:</label>
		<div class="col-xs-8"><input name="shortName" type="text"
			class="form-control" data-validation-engine="validate[required,maxSize[50]]"	placeholder="请输入组织简称"
			data-errormessage-value-missing="请输入组织简称" data-errormessage-range-overflow="简称过长(最长50位)"></div>
	</div>
	<div class="form-group">
		<label class="control-label col-xs-4"><span class="must-msg">*&nbsp;</span>公司类型:</label>
		<div class="col-xs-8"><select name="orgtype" class="form-control validate[required]"
			 data-errormessage-value-missing="请选择组织类型">
			<option value="">请选择</option>
			<option value="4">监管部门</option>
			<option value="1">主机厂</option>
			<option value="2">租赁公司</option>
			<option value="3">施工甲方</option>
		</select>
		</div>
	</div>
	<div class="form-group">
		<label class="control-label col-xs-4"><span class="must-msg">*&nbsp;</span>组织形态:</label>
		<div class="col-xs-8"><select name="type" class="form-control validate[required]"
			data-errormessage-value-missing="请选择组织类型">
				<option value="">请选择</option>
				<option value="1">公司</option>
				<option value="2">工地</option>
		</select></div>
	</div>
	<div class="form-group">
		<label class="control-label col-xs-4"><span class="must-msg">*&nbsp;</span>上级组织:</label>
		<div class="col-xs-6">
			<select name="pid" id="pid" class="form-control" data-validation-engine="validate[required]"
				 	data-errormessage-value-missing="请选择上级组织" readonly=""><option value="">请选择</option></select>
		</div>
		<div class="col-xs-2"><button class="btn btn-info" onclick="selectOrg()">选择</button></div>
	</div>
	<div class="form-group">
		<label class="control-label col-xs-4"><span class="must-msg">*&nbsp;</span>地址:</label>
		<div id="city" class="col-xs-8">
			<select name="province" id="pro" class="form-control  prov pull-left" data-validation-engine="validate[required]"
				 style="width: 33.333333%!important;">
					
			</select>
			 <select name="city" class="form-control city pull-left" data-validation-engine="validate[required]"
		 		style="width: 33.333333%!important; display: none;">
			</select>
			 <select name="area" class="form-control dist pull-left" style="width:100px"  data-validation-engine="validate[required]"
				style="width: 33.333333%!important; display: none;">
				
			</select>
			<input name="address" class="form-control" placeholder="详细地址" />
		</div>
	</div>
	<div class="form-group">
		<label class="control-label col-xs-4">邮编:</label>
		<div class="col-xs-8"><input name="zipCode" type="text" class="form-control"></div>
	</div>
	<div class="form-group">
		<label class="control-label col-xs-4">电话:</label>
		<div class="col-xs-8"><input name="phone" type="text" class="form-control"></div>
	</div>
	<div class="form-group">
		<label class="control-label col-xs-4">联系人:</label>
		<div class="col-xs-8"><input name="contacts" type="text" class="form-control"></div>
	</div>
	<div class="form-group">
		<label class="control-label col-xs-4">备注:</label>
		<div class="col-xs-8"><textarea name="desc" rows="3" class="form-control"></textarea></div>
	</div>
</form>
<script type="text/javascript">
	$("#pid").on("click",function(){
		selectOrg();
		$(this).blur();
	});
	callSvr("OrgManage/getOrgListByPid",{},function(ret){
		var $opts;
		for(var i=0;i<ret.length;i++){
			$opts+="<option value='"+ret[i].OrgId+"'>"+ret[i].Name+"</option>"
		}
		$("#pid").append($opts);
	},true);
	if(em.Operation=='create'){
		$("#city").citySelect({
			nodata : "none",
			required : false
		});
		Dialog.saveBtn.on("click", createSaveOrg);
		$("#form-org input").val("");
		$("#form-org textarea").val("");
	}else{
		callSvr("OrgManage/getOrgById", {"orgId" : em.OrgId}, function(result) {
			$("#form-org").jsonToform(result);
			$("#city").citySelect({
				prov:result.province,
				city:result.city,
				dist:result.area,
				required : false
			});
			if(em.Operation=='modify'){
				Dialog.saveBtn.on("click", modifiySaveOrg);
				$("[name='type'],[name='pid'],[name='orgtype']").attr("disabled", true);
			}else{
				$("#form-org").elementToUnable();
				Dialog.saveBtn.attr("disabled", true);
			}
		});
	}
	$("#form-org").validationEngine({
		promptPosition : 'topLeft',
		maxErrorsPerField : 1,
		showOneMessage:true,
		validateNonVisibleFields:true
	});
	function modifiySaveOrg() {
		if ($("#form-org").validationEngine('validate')) {
			if (confirm("您确定要修改该组织？")) {
				callSvr("OrgManage/modifiyOrg",$("#form-org").formToJson(), function(result) {
					if (result.err == 0) {
						toastr.success('修改成功', '');
						Dialog.exitBtn.click();
						$("#main").empty().load("../org/org.html");
					} else if (result.err == 1) {
						toastr.error('组织名称已存在', '');
					}
				});
			}
		}
	}
	function createSaveOrg() {
		if ($("#form-org").validationEngine('validate')) {
			callSvr("OrgManage/createOrg",$("#form-org").formToJson(), function(result) {
				if (result.err == 0) {
					toastr.success('新增成功', '');
					Dialog.exitBtn.click();
					$("#main").empty().load("../org/org.html");
				} else if (result.err == 1) {
					toastr.error('组织名称已存在', '');
				}
			});
		}
	}
	function selectOrg(){
		em.selectOrgDialgo=popWindowShow({
			windowId :"Random",
			popWidth :400,
			position : "center",
			src : "../org/select_org.html",
			title : "选择上级组织",
			btnShow:false
		})
	}
	function activeParentOrg(orgId){
		$("#pid").val(orgId);
		em.selectOrgDialgo.exit();
	}
</script>

